﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using 抽象工厂模式.Models;

namespace 抽象工厂模式
{
    /// <summary>
    /// 代替工厂，根据反射和配置文件 去实例化对象
    /// </summary>
    class DataAccess
    {
        //private static readonly string AssemblyName = "抽象工厂模式";
        static string AssemblyName = Assembly.GetExecutingAssembly().GetName().Name; //获取程序集名称

        // private static readonly string db = "Sql";
        //// private static readonly string db = "Access";
        //放在配置文件中
        private static readonly string db = ConfigurationManager.AppSettings["DB"];


        public static IUser CreateUser()
        {
            string className = AssemblyName+".Models" + "." + db + "User";   //命名空间.类名称
            return (IUser)Assembly.Load(AssemblyName).CreateInstance(className);
        }
        public static IDepartment CreateDepartment()
        {
            string className = AssemblyName + ".Models" + "." + db + "Department";
            return (IDepartment)Assembly.Load(AssemblyName).CreateInstance(className);
        }
    }
}
